﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Benefit.Models.Sys
{
    public class OperatorAccount
    {
        public int Id { get; set; }

        public int OperatorId { get; set; }

        public virtual Operator Operator { get; set; }

        public int AccountId { get; set; }

        public virtual Account Account { get; set; }
        ///// <summary>
        ///// 修改账户和操作员的对应关系
        ///// </summary>
        ///// <returns></returns>
        //public int AddOperatorAccount(DB.DBManager db)
        //{

        //    int oaid = 0;
        //    OperatorAccount oa = new OperatorAccount();
        //    oa.OperatorId = this.OperatorId;
        //    var query = from t in db.OperatorAccount where t.AccountId == this.AccountId select t;
        //    if (query.Count() > 0) //账户已经被配置过
        //    {
        //        oa = query.First();
        //        oa.OperatorId = this.OperatorId;
        //        db.SaveChanges();
        //        oaid = oa.Id;
        //    }
        //    else //新增的账户
        //    {
        //        oa.AccountId = this.AccountId;
        //        oa.OperatorId = this.OperatorId;
        //        db.OperatorAccount.Add(oa);
        //        db.SaveChanges();
        //        oaid = oa.Id;
        //    }
        //    return oaid;
        //}

        //public List<OperatorAccount> GetList(DB.DBManager db)
        //{
        //    var query = db.OperatorAccount.ToList();
        //    return query;
        //}
        ///// <summary>
        ///// 在网页中配置账户和操作员关系
        ///// </summary>
        ///// <param name="oas"></param>
        //public void ResetOperatorAccount(List<OperatorAccount> oas, DB.DBManager db)
        //{
        //    foreach (OperatorAccount account in oas)
        //    {
        //        var query = db.OperatorAccount.Where(a => a.AccountId == account.AccountId);
        //        if (query.Count() > 0)
        //        {
        //            OperatorAccount a = query.First();
        //            a.OperatorId = account.OperatorId;
        //        }
        //        else
        //        {
        //            db.OperatorAccount.Add(account);
        //        }
        //    }
        //    db.SaveChanges();
        //}
    }
}